export {}

interface Bird {
	name:string,
	fly():void
}

interface Person {
	name:string,
	speak():void
}
//属性全了 返回小了
type BirdMan = Bird&Person
let p1:BirdMan ={
	name:'jacck',
	fly() {},
	speak(){}
}

interface X {
	a: string;
	b: string;
}

interface Y {
	a: number;
	c: string
}

type XY = X & Y;
type YX = Y & X;
//c = string & number
//let p1: XY={a:'',b:'',c:''};


// 
type T1 = string | number
type T2 = number | boolean
type T3 = T1 & T2 // number 交叉类型 交集
type T4 = T1 | T2  // string | number | boolean 联合 并集
let t3:T3 = 12

//mixin
interface AnyObject{
	[prop:string]:any
}
function mixin<T,U>(one:T,two:U):any{
	const result = <( T & U )| unknown>{}
	for(let key in one) 
		(<T>result)[key] = one[key]

	for(let key in two) 
		(<U>result)[key] = two[key];
	return result;
}
const x = mixin({name:"jin"},{age:11})
console.log(x.name,x.age)


function mixin2<T extends AnyObject, U extends AnyObject>(one: T,two: U): T & U {
	const result = <T & U>{};
	for (let key in one) {
			(<T>result)[key] = one[key];
	}
	for (let key in two) {
			(<U>result)[key] = two[key];
	}
	return result;
}

const x2 = mixin2({ name: "jack" }, { age: 11 });
console.log(x2.name, x2.age);



//先定义类型，再定义变量
type People = {
	name:string,
	age:number,
	gender:string
}
let p3:People = {
	name:'june',
	age:10,
	gender:'male'
}

//先定义变量，再定义类型
let p4 = {
	name:'june',
	age:10,
	gender:'male'
}
type People2 = typeof p1;
function getName(p:People):string{
	return p.name;
}
getName(p4);

//索引访问操作符 
interface Person{
	name:string;
	age:number;
	job:{
			name:string
	};
	interests:{name:string,level:number}[]
}
let FrontEndJob:Person['job'] = {
	name:'前端工程师'
}
let interestLevel:Person['interests'][0]['level'] = 2;

//映射类型
interface Person6{
	name:string;
	age:number;
	gender:boolean;
}
//批量把一个接口中的属性全部变成可选的
// type PartialPerson = {
// 	[key in keyof Person6]?:Person6[key]
// }
type PPerson = Partial<Person6>

